package com.qf.springcloud.consumer.controller;

import com.qf.springcloud.consumer.feign.OrderFeign;
import com.qf.springcloud.consumer.pojo.Customer;
import com.qf.springcloud.consumer.pojo.LocalOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/customers")
public class CustomerController {

    private OrderFeign orderFeign;

    @Autowired
    public void setOrderFeign(OrderFeign orderFeign){
        this.orderFeign = orderFeign;
    }

    @GetMapping("/info/{id}")
    public Customer getById(@PathVariable Integer id) {
        Customer customer = new Customer();
        customer.setId(id);
        customer.setName("zhangsan" + id);
        customer.setAge(id + 32);
        LocalOrder order = orderFeign.getById(id);
        customer.setOrder(order);
        return customer;
    }

    @GetMapping("/test1")
    public LocalOrder test1(Integer id,String addr){
        LocalOrder order = orderFeign.suibian(id,addr);
        return order;
    }

    @GetMapping("/test2")
    public LocalOrder test2(LocalOrder order){
        return orderFeign.suibian2(order);
    }
}
